home *** CD-ROM | disk | FTP | other *** search
/ PC Media 7 / PC MEDIA CD07.iso / share / prog / cm / cmtstack.cc < prev    next >
Encoding:
Text File  |  1994-09-06  |  1.2 KB  |  48 lines

  1. // CmTStack.cc
  2. // -----------------------------------------------------------------
  3. // Compendium - C++ Container Class Library
  4. // Copyright (C) 1992-1994, Glenn M. Poorman, All rights reserved
  5. // -----------------------------------------------------------------
  6. // Stack template implementation.
  7. // -----------------------------------------------------------------
  8.  
  9.  
  10. // "CmTStack" is the stack copy constructor.
  11. //
  12. template <class T> CmTStack<T>::CmTStack(const CmTStack<T>& S)
  13.                                 : CmTLinkedList<T>(S)
  14. {}
  15.  
  16.  
  17. // "=" operator copies the contents of the input stack into this stack.
  18. //
  19. template <class T> CmTStack<T>& CmTStack<T>::operator=(const CmTStack<T>& S)
  20. {
  21.   if (&S != this) copy(S);
  22.   return *this;
  23. }
  24.  
  25.  
  26. // "push" pushes the specified item onto the top of the stack.
  27. //
  28. template <class T> Bool CmTStack<T>::push(const T& obj)
  29. {
  30.   return prepend(obj);
  31. }
  32.  
  33.  
  34. // "pop" removes the top item from the stack and returns a copy.
  35. //
  36. template <class T> T CmTStack<T>::pop()
  37. {
  38.   return removeFirst();
  39. }
  40.  
  41.  
  42. // "peek" returns a copy of the top stack item.
  43. //
  44. template <class T> const T& CmTStack<T>::peek() const
  45. {
  46.   return first();
  47. }
  48.